package com.heraleign.jsondiff;

import com.alibaba.fastjson2.JSON;
import me.codeleep.jsondiff.DefaultJsonDifference;
import me.codeleep.jsondiff.model.JsonCompareResult;
import me.codeleep.jsondiff.model.JsonComparedOption;

public class JsonDiff {
    public static void main(String[] args) {
//        String array1 = "[\n" +
//            "\t{\n" +
//            "\t\t\"year\": 2022,\n" +
//            "\t\t\"month\": 1,\n" +
//            "\t\t\"amount\": \"3000\"\n" +
//            "\t},\n" +
//            "\t{\n" +
//            "\t\t\"year\": 2022,\n" +
//            "\t\t\"month\": 2,\n" +
//            "\t\t\"amount\": \"3000\"\n" +
//            "\t},\n" +
//            "\t{\n" +
//            "\t\t\"year\": 2022,\n" +
//            "\t\t\"month\": 3,\n" +
//            "\t\t\"amount\": \"3000\"\n" +
//            "\t},\n" +
//            "\t{\n" +
//            "\t\t\"year\": 2022,\n" +
//            "\t\t\"month\": 4,\n" +
//            "\t\t\"amount\": \"3000\"\n" +
//            "\t}\n" +
//            "]";
//        String array2 = "[\n" +
//            "\t{\n" +
//            "\t\t\"year\": 2022,\n" +
//            "\t\t\"month\": 1,\n" +
//            "\t\t\"amount\": \"4000\"\n" +
//            "\t},\n" +
//            "\t{\n" +
//            "\t\t\"year\": 2022,\n" +
//            "\t\t\"month\": 2,\n" +
//            "\t\t\"amount\": \"3000\"\n" +
//            "\t},\n" +
//            "\t{\n" +
//            "\t\t\"year\": 2022,\n" +
//            "\t\t\"month\": 3,\n" +
//            "\t\t\"amount\": \"3000\"\n" +
//            "\t},\n" +
//            "\t{\n" +
//            "\t\t\"year\": 2022,\n" +
//            "\t\t\"month\": 4,\n" +
//            "\t\t\"amount\": \"2000\"\n" +
//            "\t}\n" +
//            "]";

        String array1="[\n" +
            "\t{\n" +
            "\t\t\"month\": 202201,\n" +
            "\t\t\"amount\": \"4000\"\n" +
            "\t},\n" +
            "\t{\n" +
            "\t\t\"month\": 202202,\n" +
            "\t\t\"amount\": \"3000\"\n" +
            "\t},\n" +
            "\t{\n" +
            "\t\t\"month\": 202203,\n" +
            "\t\t\"amount\": \"3000\"\n" +
            "\t},\n" +
            "\t{\n" +
            "\t\t\"month\": 202204,\n" +
            "\t\t\"amount\": \"3000\"\n" +
            "\t}\n" +
            "]";
        String array2="[\n" +
            "\t{\n" +
            "\t\t\"month\": 202201,\n" +
            "\t\t\"amount\": \"2000\"\n" +
            "\t},\n" +
            "\t{\n" +
            "\t\t\"month\": 202202,\n" +
            "\t\t\"amount\": \"3000\"\n" +
            "\t},\n" +
            "\t{\n" +
            "\t\t\"month\": 202203,\n" +
            "\t\t\"amount\": \"3000\"\n" +
            "\t},\n" +
            "\t{\n" +
            "\t\t\"month\": 202204,\n" +
            "\t\t\"amount\": \"4000\"\n" +
            "\t},\n" +
            "\t{\n" +
            "\t\t\"month\": 202205,\n" +
            "\t\t\"amount\": \"4000\"\n" +
            "\t}\n" +
            "]";
        diffKeepOrder(array1,array2);


    }


    public static void diffKeepOrder(String array1,String array2) {

        // 构建配置对象
        JsonComparedOption jsonComparedOption = new JsonComparedOption().setIgnoreOrder(true);
        // 初始化工具
        JsonCompareResult jsonCompareResult = new DefaultJsonDifference()
            .option(jsonComparedOption)
            // 对比
            .detectDiff(JSON.parseArray(array1), JSON.parseArray(array2));
        System.out.println(JSON.toJSONString(jsonCompareResult));
    }
}
